{% if field_value %}
  <table class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
      {% if permissions.SchedulerPermission.can() %}
        <th></th>
      {% endif %}
      <th>子订单号</th>
      <th>卸货点</th>
      <th>产品名称</th>
      <th>是否加急</th>
      <th>是否退镀</th>
      <th>净重 {% if not obj.measured_by_weight %}
        - 数量
      {% endif %} </th>
      {% if not obj.measured_by_weight %}
        <th>规格 - 型号</th>
      {% endif %}
      {% if permissions.SchedulerPermission.can() %}
        <th>待排产工单数</th>
        <th>
          {% if obj.measured_by_weight %}
            待预排产重量
          {% else %}
            待预排产数量
          {% endif %}
        </th>
      {% else %}
        <th>已发货重量</th>
        <th>待发货重量</th>
      {% endif %}
      <th>交货日期</th>
      <th>技术要求</th>
      <th>图片</th>
    </tr>
    </thead>
    <tbody>
    {% for sub_order in field_value %}
      <tr {% if not sub_order.refined %}class="warning" title="未完善"{% endif %}>
        {% if permissions.SchedulerPermission.can() %}
          <td>
            {% if sub_order.remaining_quantity|int > 0 and obj.refined and obj.dispatched %}
              <a class="btn btn-primary" name="{{ sub_order.id }}" href="{{ url_for('order.work_command',sub_order_id=sub_order.id,url=request.url) }}">
                {{ "质检检货" if sub_order.returned else "预排产" }}
              </a>
            {% elif not obj.refined or not obj.dispatched %}
              <em>未下发</em>
            {% endif %}
          </td>
        {% endif %}
        <td>
          <a href="{{ url_for("order.sub_order", id_=sub_order.id, url=request.url) }}">
            {{ sub_order.id }}
          </a>
        </td>
        <td>{{ sub_order.harbor.name }}</td>
        <td>{{ sub_order.product.name }}</td>
        {% if sub_order.urgent %}
          <td class="text-danger">是</td>
        {% else %}
          <td>否</td>
        {% endif %}
        {% if sub_order.returned %}
          <td class="text-danger">是</td>
        {% else %}
          <td>否</td>
        {% endif %}
        <td>{{ sub_order.weight }}(公斤) {% if not obj.measured_by_weight %}
          /{{ sub_order.quantity }}({{ sub_order.unit }})
        {% endif %} </td>
        {% if not obj.measured_by_weight %}
          <td>{{ sub_order.spec }} - {{ sub_order.type }}</td>
        {% endif %}
        {% if permissions.SchedulerPermission.can() %}
          <td {% if not sub_order.pre_work_command_list %}
            class="text-danger"
          {% endif %} >
            {{ sub_order.pre_work_command_list|length }}
          </td>
          <td
              {% if not sub_order.remaining_quantity %} class="text-danger" {% endif %} >
            {{ sub_order.remaining_quantity }}({{ sub_order.unit }})
          </td>
        {% else %}
          <td>{{ sub_order.delivered_weight }}</td>
          <td>{{ sub_order.to_deliver_weight }}</td>
        {% endif %}
        <td>{% if sub_order.due_time %}
          {{ sub_order.due_time }}{% else %}
          ----{% endif %}</td>
        <td>{{ sub_order.tech_req }}</td>
        <td>
          {% if sub_order.pic_path %}
            <a href="{{ sub_order.pic_url }}" class="fancybox thumbnail" rel="group" title="{{ sub_order.product.name }}">
              <img src="{{ sub_order.pic_url }}" class="img-responsive img-polaroid" alt="{{ sub_order.product.name }}"/>
            </a>
          {% endif %}
        </td>
      </tr>
    {% endfor %}
    <tr>
      <th>总计</th>
      {% if permissions.SchedulerPermission.can() %}
        <td></td>
      {% endif %}
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>{{ field_value|sum("weight") }} {% if not obj.measured_by_weight %}
        / {{ field_value|sum("quantity") }}
      {% endif %} </td>
      {% if not obj.measured_by_weight %}
        <td></td>
      {% endif %}
      {% if permissions.SchedulerPermission.can() %}
        <td></td>
        <td>
          {{ field_value|sum("remaining_quantity") }}
        </td>
      {% else %}
        <td>{{ field_value|sum("delivered_weight") }}</td>
        <td>{{ field_value|sum("to_deliver_weight") }}</td>
      {% endif %}

      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tbody>
  </table>
{% endif %}
